

var DataTableWidget = Class.create({
	initialize : function() {
	},

	init: function(o) {
		this.colDef = o['colDef'];
		this.title = o['title'];
		this.targetPosition = o['targetPosition'];
		this.height = "100%";
		this.width = "100%";
		 
	},
	
	
	getColDef: function() {
		return this.colDef;	
	},	
	
	setColDef: function(colDef) {
		this.colDef = coldef;
		
	},
	
	setHeight: function (h) {
		this.height = h;
	},
	
	drawTable: function(data) {
		this.cols = new Array();
		
		this.myDataSource = new YAHOO.util.DataSource(data); 
		this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY; 
		
		for ( var i = 0; i < this.colDef.length; i++) {
			this.cols[i] = this.colDef[i].key;
			
		}
		
		this.rowFormatter = function(elTr, oRecord) {
			if(oRecord.getCount()%2>0 ){
				YAHOO.util.Dom.addClass(elTr, 'tblEven');
			}else{
				YAHOO.util.Dom.addClass(elTr, 'tblOdd');
			}
			
			return true;
		};
		this.setRowFormatter(this.rowFormatter);
		this.myDataSource.responseSchema = {'fields': this.cols}; 
			 
		this.myDataTable = new YAHOO.widget.ScrollingDataTable(this.targetPosition, 
				this.colDef, this.myDataSource,{
				height:this.height,width:this.width,formatRow: this.rowFormatter
				
				} /*{'caption':this.title}*/); 
		
//		var tblHead = this.myDataTable.getHdTableEl();
//		tblHead.style.background = '#75684D';
//		tblHead.style.border = '1px solid white';
//		
//		var tblHead = this.myDataTable.getTheadEl();
//		tblHead.style.background = '#75684D';
//		tblHead.style.border = '1px solid white';
//		
		
		
		
		 
		
		var tblBody = this.myDataTable.getBdTableEl();
//		tblBody.style.background = 'url(../img/lightspeed/post_entry_bg.png)';
//		tblBody.style.width = '100%';
//		tblBody.style.border = '1px solid black';
////		tblBody.style.mozborderradiusbottomleft = '5px';
//		
//		var tblcolumnSet  = this.myDataTable.getColumnSet();
//		var colums = tblcolumnSet.flat;
//		for(var i=0; i<colums.length; i++){
////			colums[i].getColEl().style.border='1px solid black';
//			colums[i].getColEl().style.color='black';
//			colums[i].getColEl().style.padding ='0px 0px 0px 0px';
//		}
		return { 
			'oDS': this.myDataSource, 
			'oDT': this.myDataTable 
		}; 
		
	},
	
	setRowFormatter: function(rowFromatter){
		this.rowFormatter = rowFromatter;
//			function(elTr, oRecord) { 
//				if (oRecord.getData('Quantity') < 40) { 
//				  Dom.addClass(elTr, 'mark'); 
//				} 
//				return true; 
//			}; 
	}
	
});